﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Newtonsoft.Json.Linq;

namespace park.Equipment
{
    public partial class InspectionTerminalEdit : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadPageInfo();
            }
        }

        private void LoadPageInfo()
        {
            if (Request.QueryString["id"] != null)
            {
                string id = Request.QueryString["id"];
                cn.linkit.epark.ServiceList sl = new cn.linkit.epark.ServiceList();
                string strJson = sl.GetInspectionTerminalById(id);

                //string strJson = ""
                //    + "{"
                //    + "\"ID\":\"002\","
                //    + "\"No\":\"TSN4564\","
                //    + "\"Code\": \"sdgf1893\","
                //    + "\"Model\":\"ZX-T-1893\","
                //    + "\"Connection\":\"18627870000\","
                //    + "\"Description\":\"配件说明.......\","
                //    + "\"Date\":\"2012-12-05 18:00\","
                //    + "\"EmpCode\":\"SN1565212\""
                //    + "}";
                JObject obj = JObject.Parse(strJson);

                this.txtNo.Text = obj["No"].ToString();
                this.txtCode.Text = obj["Code"].ToString();
                this.txtModel.Text = obj["Model"].ToString();
                this.txtEmpNo.Text = obj["EmpCode"].ToString();
                this.txtDate.Text = obj["Date"].ToString();
                this.txtDescription.Text = obj["Description"].ToString();
                this.txtConnection.Text = obj["Connection"].ToString();
                this.hdfID.Value = obj["ID"].ToString();

            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            string no = this.txtNo.Text;
            string code = this.txtCode.Text;
            string model = this.txtModel.Text;
            string empCode = this.txtEmpNo.Text;
            DateTime date = string.IsNullOrEmpty(this.txtDate.Text) ? DateTime.Parse("1900-01-01") : DateTime.Parse(this.txtDate.Text);
            string description = this.txtDescription.Text;
            string id = this.hdfID.Value;

            cn.linkit.epark.ServiceList sl = new cn.linkit.epark.ServiceList();
            bool flag = sl.UpdateInspectionTerminal(id,no, code, model, empCode, date, description);

            if (flag)
            {
                Page.ClientScript.RegisterStartupScript(GetType(), Guid.NewGuid().ToString(), "<script>alert('数据保存成功！');</script>");
            }
            else
            {
                Page.ClientScript.RegisterStartupScript(GetType(), Guid.NewGuid().ToString(), "<script>alert('数据保存失败，请重试 ...');</script>");
            }
        }

    }
}